package logic

import (
	"context"
	"net/http"
	"week2_zg6/common/pay"

	"week2_zg6/bookApi/internal/svc"
	"week2_zg6/bookApi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PayLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPayLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PayLogic {
	return &PayLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PayLogic) Pay(req *types.PayRequest) (resp *types.PayResponse, err error) {
	pays, err := pay.Pays(req.OrderID, req.Price)
	if err != nil {
		return nil, err
	}
	return &types.PayResponse{
		Code: http.StatusOK,
		Msg:  pays,
		Date: nil,
	}, nil
}
